// pages/detail/detail.js
import { request } from '../../utils/wxCommon'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list:{},
    showBtn: false,//是否展示编辑删除按钮
  },
  //跳转到编辑的页面
  goEdit(){
    wx.navigateTo({
      url: '/pages/edit/edit',
    })
  },
  //删除当前的文章
  removeArticle(){
    wx.showModal({
      cancelText: '在想想',
      confirmText: '删除',
      content: '确定要删除当前的文章吗？',
      success: res=>{
        if(res.confirm){
          const params = {
            openid: this.data.list.openid,
            id: this.data.list._id,
            type: 7
          }
          request('user',params).then(res=>{
            console.log(res);
            if(res.result.status === 'S'){//删除成功返回上一页
              wx.navigateBack({
                delta: 1,
              })
            }
          }).catch(msg=>{
            console.log(msg);
          })
        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
     const list = wx.getStorageSync('detail') || {};
     const openid = wx.getStorageSync('usreInfo').openid || ''
     list.detail = list.detail.replace(/\<img/gi, '<img style="max-width:100%;height:auto" ');
      this.setData({
        list,
        showBtn: openid === list.openid ? true : false
      })
  },

})